use askama::Template;
use axum::{extract::Query, response::IntoResponse};
use tower_cookies::Cookies;

use crate::{domain::topic::Topic, service::topic_service, QueryParam, TemplateResponse};

use super::base::{base, BaseData};
use crate::template::filters;

#[derive(Template)]
#[template(path = "post.html")]
pub struct PostTemplate {
    topic: Option<Topic>,
    base: BaseData,
}
pub async fn index(cookies: Cookies, param: Query<QueryParam>) -> impl IntoResponse {
    let topic = if let Some(id) = param.0.id {
        let topic = topic_service::select_by_id(id).await;
        Some(topic)
    } else {
        None
    };
    let template = PostTemplate {
        topic,
        base: base(cookies).await,
    };
    TemplateResponse(template)
}
